package com.ruoyi.tranShort.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.WebSocketTypeConstants;
import com.ruoyi.tranShort.domain.WebSocketEntity;
import com.ruoyi.tranShort.mqtt.api.WristletWriteBackCallBack;
import com.ruoyi.tranShort.webSocked.WristletWebsocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wwy
 * @date 2021-08-14 10:19
 */
@Component
public class MyWristletWriteBackCallBack implements WristletWriteBackCallBack {
    @Autowired
    private WristletWebsocketServer wristletWebsocketServer;
    @Override
    public void invoke(String mac) {
        //手动叫哨消息回复判断
        if(WristletServiceImpl.sendMacList.contains(mac.toUpperCase())){
            //存在
            WebSocketEntity webSocketEntity = new WebSocketEntity();
            webSocketEntity.setCode(200);
            webSocketEntity.setType(WebSocketTypeConstants.MANUAL_SEND);
            webSocketEntity.setDeviceCode(mac);
            String webSocketEntityJson = JSONObject.toJSONString(webSocketEntity);
            wristletWebsocketServer.sendAll(webSocketEntityJson);
        }

        if(WristletServiceImpl.autoSendMacList.contains(mac.toUpperCase())){
            //存在
            WebSocketEntity webSocketEntity = new WebSocketEntity();
            webSocketEntity.setCode(200);
            webSocketEntity.setType(WebSocketTypeConstants.AUTO_SEND);
            webSocketEntity.setDeviceCode(mac);
            String webSocketEntityJson = JSONObject.toJSONString(webSocketEntity);
            wristletWebsocketServer.sendAll(webSocketEntityJson);
        }

    }
}
